//
//  Carousel.m
//  GTMDBTest
//
//  Created by dllo on 15/11/26.
//  Copyright © 2015年 zxx. All rights reserved.
//

#import "Carousel.h"

#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height

@implementation Carousel

- (instancetype)initWithFrame:(CGRect)frame array:(NSArray *)array subString:(NSString *)subString {
    self = [super initWithFrame:frame];
    if (self) {
        [self createCarouselWithFrame:(CGRect)frame array:(NSArray *)array subString:subString];
    }
    return self;
}

- (void)createCarouselWithFrame:(CGRect)frame array:(NSArray *)array subString:(NSString *)subString {
    
    self.contentSize = CGSizeMake(array.count * WIDTH, 0);
    
    UIImageView *firstImageView = [[UIImageView alloc] initWithFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height)];
    firstImageView.backgroundColor = [UIColor orangeColor];
    [self addSubview:firstImageView];
    
    UILabel *firstBgLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height - 25 * HEIGHT / 667.0, frame.size.width, 30 * HEIGHT / 667.0)];
    firstBgLabel.backgroundColor = [UIColor blackColor];
    firstBgLabel.alpha = 0.7;
    [firstImageView addSubview:firstBgLabel];
    
    UILabel *firstLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height - 25 * HEIGHT / 667.0, frame.size.width, 30 * HEIGHT / 667.0)];
    firstLabel.textColor = [UIColor whiteColor];
    firstLabel.text = @"0sdgsdgs";
    [firstImageView addSubview:firstLabel];

    for (NSInteger i = 0; i < array.count; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(frame.size.width * (i + 1), frame.origin.y, frame.size.width, frame.size.height)];
        imageView.backgroundColor = [UIColor orangeColor];
        [self addSubview:imageView];
        
        UILabel *bgLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height - 25 * HEIGHT / 667.0, frame.size.width, 30 * HEIGHT / 667.0)];
        bgLabel.backgroundColor = [UIColor blackColor];
        bgLabel.alpha = 0.7;
        [imageView addSubview:bgLabel];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height - 25 * HEIGHT / 667.0, frame.size.width, 30 * HEIGHT / 667.0)];
        label.textColor = [UIColor whiteColor];
        label.text = @"0sdgsdgs";
        [imageView addSubview:label];
    }
    
    UIImageView *lastImageView = [[UIImageView alloc] initWithFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height)];
    lastImageView.backgroundColor = [UIColor orangeColor];
    [self addSubview:lastImageView];
    
    UILabel *lastBgLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, frame.size.height - 25 * HEIGHT / 667.0, frame.size.width, 30 * HEIGHT / 667.0)];
    lastBgLabel.backgroundColor = [UIColor blackColor];
    lastBgLabel.alpha = 0.7;
    [lastImageView addSubview:lastBgLabel];
    
    UILabel *lastLabel = [[UILabel alloc] initWithFrame:CGRectMake(frame.size.width * (array.count + 1), frame.size.height - 25 * HEIGHT / 667.0, frame.size.width, 30 * HEIGHT / 667.0)];
    lastLabel.textColor = [UIColor whiteColor];
    lastLabel.text = @"0sdgsdgs";
    [lastImageView addSubview:lastLabel];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
